package com.tungse.study.scheedule;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author Tungse
 */
public class ScheduleMain {
    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");

    public static void main(String[] args) throws Exception {
        ScheduleService scheduleService = new ScheduleService();


        System.out.println("添加一个每1000毫秒打印一次的定时任务");
        scheduleService.schedule( () -> {
            System.out.println(LocalDateTime.now().format(DATE_TIME_FORMATTER) + "这是每1000毫秒打印一次的定时任务");
        }, 0, 1000);


        Thread.sleep(1000);

        System.out.println("添加一个2000毫秒后打印一次定时任务");
        scheduleService.execute(() -> {
            System.out.println(LocalDateTime.now().format(DATE_TIME_FORMATTER) + "这是2000毫秒只打印一次的定时任务");
        }, 2000);
    }
}